<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>疫情上报记录 - Powered by __CAOZHA-SYS-NAME__ __CAOZHA-SYS-VERSION__</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__CAOZHA-LAYUIMINI__/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__CAOZHA-LAYUIMINI__/css/public.css" media="all">
    <script src="__CAOZHA-STATIC__/js/all.js"></script>
    <link rel="stylesheet" href="__CAOZHA-STATIC__/css/style.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <style>
            body .caozha-record-form .layui-form-select .layui-input{height: 32px; }
        </style>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container cz-float-left">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"
                        lay-event="delete"> 删除
                </button>
            </div>
            <div class="cz-toolbar-search cz-float-left" style="width: 520px;">
                <form class="layui-form layui-form-pane caozha-record-form" action="">
                    <div style="width: 175px;float: left;color: #595959">
                        <div style="width: 45px;float: left">症状：</div><div style="width: 120px;float: left"><select name="symptom" id="symptom" lay-filter="symptom">
                        <option value=""></option>
                        <option value="1">≥37.3度或咳嗽</option>
                        <option value="2">37.3度以下</option>
                    </select></div>
                    </div>
                     <input name="keyword" class="cz-toolbar-search-input" placeholder="请输入关键词">
                    <button type="submit" class="layui-icon layui-icon-search cz-toolbar-search-btn" lay-submit
                            lay-filter="data-search-btn" style="left: 303px;"></button>                             
                </form>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-primary data-count-view" lay-event="view">详情</a>
        </script>


    </div>
</div>
<script src="__CAOZHA-LAYUIMINI__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '{:url(\'admin/record/get\')}',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": "0", //解析接口状态 res.status
                    "msg": "", //解析提示文本 res.message
                    "count": res.total, //解析数据长度
                    "data": res.data //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['exports','filter', 'print', {
                title: '提示：双击可查看详情',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            even: false,//隔行背景
            size: "",//sm （小尺寸）       lg （大尺寸）
            cols: [[
                {type: "checkbox",width: 40,  align: "center"},
                {field: 'record_id', width: 80,title: 'ID', sort: true},
                {field: 'user_id',width: 85, title: '用户ID'},
                {field: 'name',width: 90, title: '姓名'},
                {field: 'company',minWidth: 165, title: '所属公司'},
                {field: 'temperature', width: 75,  title: '体温'},
                {field: 'is_cough',width: 75, title: '咳嗽'},
                {field: 'type',width: 115, title: '记录类型'},
                {field: 'state',width: 85, title: '状态'},
                {field: 'add_time',width: 165, title: '上报时间'},
                {field: 'idcard', width: 175, title: '身份证号'},
                {field: 'tel',width: 120, title: '手机'},
                {field: 'remarks',minWidth: 160, title: '用户备注'},
                {title: '查看', width: 80, toolbar: '#currentTableBar', align: "center", fixed: "right"}
            ]],
            limits: [5, 10, 15, 20, 25, 50, 100, 200, 500, 1000],
            limit: {$record_limit},
            page: true,
            skin: 'line'
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var record_id_arr = $.map(data, function (d) {
                    return d.record_id;
                });
                var record_id_str = record_id_arr.join(",");//转为字符串

                if (record_id_str == "") {
                    // var caozha_error=layer.alert('请先选择的数据。', {
                    //      title:'错误提示',
                    //      btn: ['确定'],
                    //      skin: 'layui-layer-molv' //样式类名
                    //      ,closeBtn: 0,
                    //      btnAlign: 'c',
                    //      icon: 5,
                    //  }, function(){
                    //     layer.close(caozha_error);
                    //      });
                    layer.msg('请先选择要删除的数据。', {icon: 2});
                    return false;
                }

                caozha_alert = layer.confirm('确定要删除ID为[ ' + record_id_str + ' ]的疫情上报记录吗？<br>删除后无法撤销。', {
                    btn: ['确认删除', '取消删除'],
                    btnAlign: 'c',
                    title: "操作提示"
                }, function () {

                    $.ajax({
                        type: "post",
                        url: '{:url(\'admin/record/delete\')}',
                        data: {record_id: record_id_str},
                        dataType: "json",
                        async: false,
                        success: function (del_data) {
                            if (del_data.code == 1) {
                                layer.msg('删除成功，共删除' + del_data.del_num + '个用户！', {icon: 1});
                                //执行删除后重载
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                            } else {
                                layer.msg('删除失败', {icon: 2});
                            }
                        }
                    });
                    layer.close(caozha_alert);//关闭

                });

            }
        });

        // 监听搜索操作：下拉框
        form.on('select(symptom)', function (data) {

            var result = data.value;

            console.log(result);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    keyword: "",
                    symptom:result
                }
            }, 'data');
            $("#symptom").val(result);//重新赋值

            return false;
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

            var result = data.field;

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    keyword: result.keyword,
                    symptom:""
                }
            }, 'data');
            $(".cz-toolbar-search-input").val(result.keyword);//重新赋值搜索框

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        //监听行双击事件
        table.on('rowDouble(currentTableFilter)', function(obj){
            //console.log(obj.tr) //得到当前行元素对象
            //console.log(obj.data) //得到当前行数据
            //obj.del(); //删除当前行
            //obj.update(fields) //修改当前行数据

            var record_data = obj.data;

            var index = layer.open({
                title: '查看疫情上报记录',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['50%', '85%'],
                content: '{:url(\'admin/record/view\')}?record_id='+record_data.record_id,
            });

            return false;


        });

        //查看
        table.on('tool(currentTableFilter)', function (obj) {
            var record_data = obj.data;
            if (obj.event === 'view') {

                var index = layer.open({
                    title: '查看疫情上报记录',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['50%', '85%'],
                    content: '{:url(\'admin/record/view\')}?record_id='+record_data.record_id,
                });
                return false;

            }
        });


    });

</script>

</body>
</html>